﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using ESRI.ArcGIS.Geometry;
using SysCommon.Interface.StakeoutCar;
using AppCommon.Framework;
using SysCommon.Entity;


namespace TMSIM.Client.BizGIS.Business
{
    class DisplayCarsCtrlHelper
    {
        private Bitmap _carIcon = null;
        private Bitmap _poisonouscarIcon = null;
        private Bitmap _bufferIcon = null;
        private IPoint _point = new PointClass();
        private ArrayList list = new ArrayList();
        private ArrayList listpoisonous = new ArrayList();
        private  SysCommon.Entity.TMSIM.WS.BaseData.Car_Ety[] c_ety = null;
        private Dictionary<string, string> DicDangerPlan = new Dictionary<string, string>();
        public Dictionary<int, SysCommon.Entity.Business.DCS.View.View_DangerPlan_EtyEx> dcs = new Dictionary<int, SysCommon.Entity.Business.DCS.View.View_DangerPlan_EtyEx>();
        //private List<SysCommon.Entity.TMSIM.WS.Query.Car_Ety> list = new List<SysCommon.Entity.TMSIM.WS.Query.Car_Ety>();
        //private List<SysCommon.Entity.TMSIM.WS.Query.Car_Ety> listpoisonous = new List<SysCommon.Entity.TMSIM.WS.Query.Car_Ety>();
        /// <summary>
        /// 获得车辆的类型
       /// </summary>
        /// <param name="etys"></param>
        public void DisplayCars(SysCommon.Entity.Business.LatestGPS_Ety[] etys)
        {
            if (_carIcon == null)
            {
                string path = System.Windows.Forms.Application.StartupPath + @"\ico\Br.bmp";
                _carIcon = new Bitmap(path);
                _carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
            }
            if (_poisonouscarIcon == null)
            {
                string path1 = System.Windows.Forms.Application.StartupPath + @"\ico\Poisonous1.bmp";
                _poisonouscarIcon = new Bitmap(path1);
                _poisonouscarIcon = new Bitmap(_poisonouscarIcon, new Size(_poisonouscarIcon.Width / 4, _poisonouscarIcon.Height / 4));
            }
            if (TMSIM.Client.BizGIS.BGISGlobal.MapCtrl != null)
            {
                if (_bufferIcon == null)
                {
                    _bufferIcon = new Bitmap(
                        TMSIM.Client.BizGIS.BGISGlobal.MapCtrl.Width,
                        TMSIM.Client.BizGIS.BGISGlobal.MapCtrl.Height);
                }
                using (Graphics g = TMSIM.Client.BizGIS.BGISGlobal.MapCtrl.CreateGraphics())
                {
                   
                }
            }
        }

        public void DisplayCarByMap(Dictionary<string, int> Dicgps)
        {
            IBGIS_GetCarByRoadBIZCtrl m_BGIS = (IBGIS_GetCarByRoadBIZCtrl)SystemFactory.GetBizController(typeof(IBGIS_GetCarByRoadBIZCtrl));
            int scale = m_BGIS.GetMapScale();
            //if (scale == 1)
            //{
            //    string path = System.Windows.Forms.Application.StartupPath + @"\ico\Br.bmp";
            //    _carIcon = new Bitmap(path);
            //    //_carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
            //    _carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 2, _carIcon.Height / 2));
            //}
            //if (scale == 2)
            //{
            //    string path = System.Windows.Forms.Application.StartupPath + @"\ico\Br.bmp";
            //    _carIcon = new Bitmap(path);
            //    //_carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
            //    _carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 3, _carIcon.Height / 3));
            //}
            //if (scale == 3)
            ////{
                string path = System.Windows.Forms.Application.StartupPath + @"\ico\Br.bmp";
                _carIcon = new Bitmap(path);
                //_carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
                _carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
            //}
            //if (_carIcon == null)
            //{
            //    string path = System.Windows.Forms.Application.StartupPath + @"\ico\Br.bmp";
            //    _carIcon = new Bitmap(path);
            //    //_carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width / 4, _carIcon.Height / 4));
            //    _carIcon = new Bitmap(_carIcon, new Size(_carIcon.Width/2, _carIcon.Height/2 ));
            //}
            double LONGITUDE,LATITUDE;
            int i = 0;
            foreach (string gpsstr in Dicgps.Keys)
            {
              
                int x, y;

                i = Dicgps[gpsstr];
                LONGITUDE = Convert.ToDouble(gpsstr.Split('_')[0]);
                LATITUDE = Convert.ToDouble(gpsstr.Split('_')[1]);
                _point.PutCoords(LONGITUDE, LATITUDE);
                 TMSIM.Client.BizGIS.BGISGlobal.MapCtrl.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(
                    _point, out x, out y);
                 

                using (Graphics g = TMSIM.Client.BizGIS.BGISGlobal.MapCtrl.CreateGraphics())
                {
                    if (scale == 1)
                    {
                        //g.DrawImage(_carIcon, x, y);
                        System.Drawing.Point point = new System.Drawing.Point(x, y);
                        //point.Offset(-25, -25);
                        Size size = new Size(35, 35);
                        Pen blackPen = new Pen(Color.Red, 1);
                        Rectangle rect = new Rectangle(point, size);
                        g.DrawEllipse(blackPen, rect);
                        //Rectangle rect = new Rectangle(point, size);
                        Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                        //Brush brush1 = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
                        //g.FillRectangle(brush1, rect);
                        Pen pen = new Pen(Color.Gray);
                        //g.DrawRectangle(pen, rect);
                        Font font = new Font("宋体", 9F);
                        //g.DrawString("aa", font, brush, point);
                        point.Offset(13, 13);
                        g.DrawString(i.ToString(), font, brush, point);

                    }
                    else
                    {
                        g.DrawImage(_carIcon, x, y);
                        
                    
                    }

                 }
                  
                }
            }
                       
                    
       
      
    }
}
